if WScript.Arguments.Count = 0 then
    WScript.Echo "Missing parameters"
    WScript.Quit 0
end if

Dim revisionHash
revisionHash = "0000000"
Dim buildNr
buildNr = -1
Dim branchName
branchName = "unknown"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim filename
filename = WScript.Arguments(0) & "BuildProperties.cs"

'we assume that only the build server sets the correct parameters otherwise this must be a local build
if WScript.Arguments.Count > 1 then
    buildNr = WScript.Arguments(1)
    branchName = WScript.Arguments(2)
    revisionHash = WScript.Arguments(3)
else
    'create local buildproperties.cs file only if it not exists
    if (fso.FileExists(filename)) then WScript.Quit 0
    WScript.Echo "Local build"
end if

Dim genereatedFile
Set genereatedFile = fso.CreateTextFile(filename, True)
genereatedFile.WriteLine "//warning: autogenerated file. do not edit."
genereatedFile.WriteLine "using System;" & vbCrLf
genereatedFile.WriteLine "namespace Framefield.Core"
genereatedFile.WriteLine "{"
genereatedFile.WriteLine "    public static class BuildProperties"
genereatedFile.WriteLine "    {"
genereatedFile.WriteLine "        public static int Build { get { return " & buildNr & "; } }"
genereatedFile.WriteLine "        public static string Branch { get { return """ & branchName & """; } }"
genereatedFile.WriteLine "        public static string Commit { get { return """ & revisionHash & """; } }"
genereatedFile.WriteLine "        public static string CommitShort { get { return Commit.Substring(0, 7); } }"
genereatedFile.WriteLine "    }"
genereatedFile.WriteLine "}"

rem WScript.Echo filename & " generated"
